<?php
namespace app\admin\controller;
use think\facade\{View,Session,Db};
use app\BaseController;

class Index extends Base
{

    public function index()
    {
        //初始化页面
        return View::fetch('index/index');
    }
    //首页
    public function index1(){
        
        return View::fetch('index/index1');
    }
    // 获取统计
    public function statics(){
       $data=[];
       $data["value1"]=Db::name("order")->where("status",1)->where("addtime",">",strtotime(date('Y-m-d')))->count();//今日订单数
       $data["value2"]=Db::name("order")->where("status",1)->where("addtime",">",strtotime(date('Y-m-d')))->sum("price");//今日订单金额
       $data["value3"]=Db::name("order")->where("is_tk",1)->where("tk_time",">",strtotime(date('Y-m-d')))->count();//今日退款数
       $data["value4"]=Db::name("order")->where("is_tk",1)->where("tk_time",">",strtotime(date('Y-m-d')))->sum("price");//今日退款数
       
       $data["value5"]=Db::name("order")->where("status",1)->whereMonth("addtime")->count();  //本月订单数
       $data["value6"]=Db::name("order")->where("status",1)->whereMonth("addtime")->sum("price");  //本月订单数
       $data["value7"]=Db::name("order")->where("is_tk",1)->whereMonth("tk_time")->count();//今日退款数
       $data["value8"]=Db::name("order")->where("is_tk",1)->whereMonth("tk_time")->sum("price");//今日退款数
       

       $data["value9"]=Db::name("order")->where("status",1)->where("is_tk",0)->sum("price");  //汇总订单金额
     
        return returnmsg(200,"检索成功",$data);
    }
    public function searchRt(){
       
        $months=[];
        //最近半年时间 -及时间段 依次列出
        $months_cn=["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"];
        
        $time=date("Y-m-01");
        $data=[];
        $order_label=[];
        for($i=0;$i<=11;$i++){
            
            $data[$i]['month']=date("Y-m-01 00:00:00", strtotime( $time . " -{$i} month"));
            $data[$i]['label_key']=date("m", strtotime( $time.  " -{$i} month"));
            $order_label[]=$months_cn[  $data[$i]['label_key']*1-1 ];
            
            
        }
        $order_label=array_reverse($order_label);
        $data=array_reverse($data);
       
        $rdata=[];
         $rdata1=[];

        foreach($data as $k => $v){
            $eo=[];//时间封装
            $time1=strtotime($v['month']);
            $time2=strtotime('+1 month',$time1);
   
            $eo[]=['addtime','between',[$time1,$time2]];
      
                $count1 = Db::name("order")->where("search_type",0)->where($eo)->count();
          
                  $count = Db::name("order")->where("search_type",1)->where($eo)->count();
          
         
            $rdata[]=$count;
            $rdata1[]=$count1;
          
        }
        
        View::assign('msg',json_encode([
            'rdata'=>$rdata,'rdata1'=>$rdata1,'label'=>$order_label
        ]));
    
    }


   
}
